package com.helloscala.web

import net.liftweb.http.RewriteRequest
import com.helloscala.model.MUser
import com.helloscala.helper.HelloHelpers

object ValidSiteId {
  def unapply(rq: RewriteRequest): Option[MyRewriteRequest] = {
    if (HelloHelpers.config.two_domain_support)
      rq.httpRequest.serverName.split('.') match {
        case Array(ValidSiteId(siteId), _, _) if rq.path.partPath.headOption.exists(v => v == "index" || !MUser.invalidId(v)) =>
          Some(MyRewriteRequest(siteId, rq.path.partPath, rq))

        case _ =>
          None
      }
    else
      None
  }

  def unapply(v: String): Option[String] = {
    //    if (HelloRules.userIds.contains(v)) Some(v) // 在用户注册时就限制了ID的有限性，在此只需要在缓存中查看是否存在此ID即可。
    if (MUser.allowedId(v)) Some(v)
    else None
  }
}



